package com.ztsoft.user.service.project.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ztsoft.user.mapper.project.ExpendMapper;
import com.ztsoft.user.pojo.entity.project.PExpend;
import com.ztsoft.user.pojo.entity.project.PModel;
import com.ztsoft.user.pojo.page.PageQuery;
import com.ztsoft.user.service.project.ExpendService;
import com.ztsoft.user.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * @author 12487
 */
@Service
public class ExpendServiceImpl extends ServiceImpl<ExpendMapper, PExpend> implements ExpendService {
    @Resource
    public ExpendMapper expendMapper;
    @Override
    public Result<Object> list(PExpend bo, PageQuery pageQuery) {
        QueryWrapper<PExpend> lqw =new QueryWrapper();
        lqw.like(ObjectUtil.isNotEmpty(bo.getExpendName()),"expend_name",bo.getExpendName());
        lqw.eq(ObjectUtil.isNotEmpty(bo.getProjectId()),"project_id",bo.getProjectId());
        Page<PExpend> result = expendMapper.selectPage(pageQuery.build(),lqw);
        return Result.success(result);
    }

    @Override
    public Result<Object> expendOne(String id) {
        return Result.success(expendMapper.selectById(id));
    }

    @Override
    public Result<Object> add(PExpend bo) {
        return Result.success(expendMapper.insert(bo));
    }

    @Override
    public Result<Object> update(PExpend bo) {
        return Result.success(expendMapper.updateById(bo));
    }

    @Override
    public Result<Object> delete(String[] ids) {
        return Result.success(expendMapper.deleteBatchIds(Arrays.asList(ids)));
    }

    /**
     * 合计 根据项目
     * @param projectId
     * @return
     */
    @Override
    public Result<Object> total(String projectId) {
        String total  = expendMapper.total(projectId);
        return Result.success(total);
    }
}
